USE [DentalSoftware]
GO
/****** Object:  ForeignKey [FK_BenhNhan_DanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucLoaiBenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_DanhMucLoaiBenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan_DanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucNgheNghiep]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_DanhMucNgheNghiep]
GO
/****** Object:  ForeignKey [FK_BenhNhan_Quan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_Quan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_Quan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-BenhTienSu_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] DROP CONSTRAINT [FK_BenhNhan-BenhTienSu_BenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] DROP CONSTRAINT [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Phieu_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] DROP CONSTRAINT [FK_BenhNhan-Phieu_BenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Phieu_Phieu]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_Phieu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] DROP CONSTRAINT [FK_BenhNhan-Phieu_Phieu]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Rang_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Rang_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]'))
ALTER TABLE [dbo].[BenhNhan-Rang] DROP CONSTRAINT [FK_BenhNhan-Rang_BenhNhan]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_BenhNhan]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_DanhMucDichVu]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_DotDieuTri]
GO
/****** Object:  ForeignKey [FK_DotDieuTri_BacSi]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BacSi]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] DROP CONSTRAINT [FK_DotDieuTri_BacSi]
GO
/****** Object:  ForeignKey [FK_DotDieuTri_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] DROP CONSTRAINT [FK_DotDieuTri_BenhNhan]
GO
/****** Object:  ForeignKey [FK_DotDieuTri-DichVu_DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] DROP CONSTRAINT [FK_DotDieuTri-DichVu_DanhMucDichVu]
GO
/****** Object:  ForeignKey [FK_DotDieuTri-DichVu_DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] DROP CONSTRAINT [FK_DotDieuTri-DichVu_DotDieuTri]
GO
/****** Object:  ForeignKey [FK_LichHen_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LichHen_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[LichHen]'))
ALTER TABLE [dbo].[LichHen] DROP CONSTRAINT [FK_LichHen_BenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteChiTietDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteChiTietDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDotDieuTri-DichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertChiTietDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertChiTietDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDotDieuTri-DichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateChiTietDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateChiTietDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDotDieuTri-DichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectChiTietDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTriByDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTriByDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectChiTietDieuTriByDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTrisAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTrisAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectChiTietDieuTrisAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDotDieuTri-DichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri-DichVusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri-DichVusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDotDieuTri-DichVusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateChiTietDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateChiTietDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateChiTietDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDotDieuTri-DichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateBenhNhan-BenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan-Phieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateBenhNhan-Phieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectRangByMaBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectRangByMaBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectRangByMaBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTrisAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTrisAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDotDieuTrisAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan_Rang]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan_Rang]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateBenhNhan_Rang]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan-Phieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateBenhNhan-Phieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhan-BenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-BenhTienSusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-BenhTienSusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhan-BenhTienSusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-Phieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhan-Phieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-PhieusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-PhieusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhan-PhieusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan_Rang]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan_Rang]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertBenhNhan_Rang]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertBenhNhan-BenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan-Phieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertBenhNhan-Phieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDotDieuTri]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteBenhNhan-BenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan-Phieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteBenhNhan-Phieu]
GO
/****** Object:  Table [dbo].[DotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] DROP CONSTRAINT [FK_DotDieuTri-DichVu_DanhMucDichVu]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] DROP CONSTRAINT [FK_DotDieuTri-DichVu_DotDieuTri]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]') AND type in (N'U'))
DROP TABLE [dbo].[DotDieuTri-DichVu]
GO
/****** Object:  Table [dbo].[ChiTietDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_DanhMucDichVu]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] DROP CONSTRAINT [FK_ChiTietDieuTri_DotDieuTri]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]') AND type in (N'U'))
DROP TABLE [dbo].[ChiTietDieuTri]
GO
/****** Object:  Table [dbo].[BenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] DROP CONSTRAINT [FK_BenhNhan-BenhTienSu_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] DROP CONSTRAINT [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]') AND type in (N'U'))
DROP TABLE [dbo].[BenhNhan-BenhTienSu]
GO
/****** Object:  Table [dbo].[BenhNhan-Phieu]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] DROP CONSTRAINT [FK_BenhNhan-Phieu_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_Phieu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] DROP CONSTRAINT [FK_BenhNhan-Phieu_Phieu]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]') AND type in (N'U'))
DROP TABLE [dbo].[BenhNhan-Phieu]
GO
/****** Object:  Table [dbo].[BenhNhan-Rang]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Rang_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]'))
ALTER TABLE [dbo].[BenhNhan-Rang] DROP CONSTRAINT [FK_BenhNhan-Rang_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]') AND type in (N'U'))
DROP TABLE [dbo].[BenhNhan-Rang]
GO
/****** Object:  Table [dbo].[LichHen]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LichHen_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[LichHen]'))
ALTER TABLE [dbo].[LichHen] DROP CONSTRAINT [FK_LichHen_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LichHen]') AND type in (N'U'))
DROP TABLE [dbo].[LichHen]
GO
/****** Object:  Table [dbo].[DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BacSi]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] DROP CONSTRAINT [FK_DotDieuTri_BacSi]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] DROP CONSTRAINT [FK_DotDieuTri_BenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DotDieuTri]') AND type in (N'U'))
DROP TABLE [dbo].[DotDieuTri]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaBNMax]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaBNMax]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_GetMaBNMax]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhansAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhansAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhansAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhanByHoTen]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhanByHoTen]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhanByHoTen]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhanByThongTin]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhanByThongTin]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBenhNhanByThongTin]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBacSi]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBacSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateBacSi]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDanhMucBenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucDichVu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucDichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDanhMucDichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDanhMucLoaiBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateDanhMucNgheNghiep]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdatePhieu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdatePhieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdatePhieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateQuan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateQuan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_UpdateQuan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdatePhieu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdatePhieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdatePhieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateQuan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateQuan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateQuan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBacSi]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBacSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBacSi]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBacSisAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBacSisAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectBacSisAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectPhieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieuByNgayDauNgayCuoi]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieuByNgayDauNgayCuoi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectPhieuByNgayDauNgayCuoi]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectPhieusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectQuan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectQuan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectQuan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectQuansAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectQuansAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectQuansAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucBenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucBenhTienSusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucBenhTienSusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucBenhTienSusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucDichVu]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucDichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucDichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucDichVusAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucDichVusAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucDichVusAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucLoaiBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucLoaiBenhNhansAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucNgheNghiep]
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucNgheNghiepsAll]    Script Date: 12/23/2012 13:49:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucNgheNghiepsAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_SelectDanhMucNgheNghiepsAll]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDanhMucBenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucDichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDanhMucDichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateDanhMucNgheNghiep]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertPhieu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertPhieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertPhieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertQuan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertQuan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertQuan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBacSi]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBacSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertUpdateBacSi]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDanhMucBenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucDichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDanhMucDichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDanhMucLoaiBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertDanhMucNgheNghiep]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaPhieuThuChiMax]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaPhieuThuChiMax]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_GetMaPhieuThuChiMax]
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBacSi]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBacSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_InsertBacSi]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeletePhieu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeletePhieu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeletePhieu]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteQuan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteQuan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteQuan]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaBacSiMax]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaBacSiMax]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_GetMaBacSiMax]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBacSi]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBacSi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteBacSi]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDanhMucBenhTienSu]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucDichVu]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDanhMucDichVu]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDanhMucLoaiBenhNhan]
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_DeleteDanhMucNgheNghiep]
GO
/****** Object:  Table [dbo].[BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucLoaiBenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_DanhMucLoaiBenhNhan]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucNgheNghiep]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_DanhMucNgheNghiep]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_Quan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] DROP CONSTRAINT [FK_BenhNhan_Quan]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan]') AND type in (N'U'))
DROP TABLE [dbo].[BenhNhan]
GO
/****** Object:  Table [dbo].[DanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucBenhTienSu]') AND type in (N'U'))
DROP TABLE [dbo].[DanhMucBenhTienSu]
GO
/****** Object:  Table [dbo].[DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucDichVu]') AND type in (N'U'))
DROP TABLE [dbo].[DanhMucDichVu]
GO
/****** Object:  Table [dbo].[DanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucLoaiBenhNhan]') AND type in (N'U'))
DROP TABLE [dbo].[DanhMucLoaiBenhNhan]
GO
/****** Object:  Table [dbo].[DanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucNgheNghiep]') AND type in (N'U'))
DROP TABLE [dbo].[DanhMucNgheNghiep]
GO
/****** Object:  Table [dbo].[BacSi]    Script Date: 12/23/2012 13:49:57 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BacSi]') AND type in (N'U'))
DROP TABLE [dbo].[BacSi]
GO
/****** Object:  Table [dbo].[Phieu]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Phieu]') AND type in (N'U'))
DROP TABLE [dbo].[Phieu]
GO
/****** Object:  Table [dbo].[PhongRang]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PhongRang]') AND type in (N'U'))
DROP TABLE [dbo].[PhongRang]
GO
/****** Object:  Table [dbo].[Quan]    Script Date: 12/23/2012 13:49:58 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Quan]') AND type in (N'U'))
DROP TABLE [dbo].[Quan]
GO
/****** Object:  Table [dbo].[Quan]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Quan]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Quan](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
 CONSTRAINT [PK_Quan] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[PhongRang]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PhongRang]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PhongRang](
	[Ma] [nchar](10) NOT NULL,
	[Ten] [nvarchar](50) NULL,
	[DiaChi] [nvarchar](50) NULL,
	[DienThoai] [nvarchar](50) NULL,
	[Web] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
 CONSTRAINT [PK_PhongRang] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Phieu]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Phieu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Phieu](
	[Ma] [int] NOT NULL,
	[Ngay] [datetime] NULL,
	[NguoiThucHien] [nvarchar](50) NULL,
	[DiaChi] [nvarchar](100) NULL,
	[DienThoai] [nvarchar](50) NULL,
	[NoiDung] [nvarchar](100) NULL,
	[SoTien] [float] NULL,
	[Loai] [int] NULL,
 CONSTRAINT [PK_Phieu] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BacSi]    Script Date: 12/23/2012 13:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BacSi]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BacSi](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
	[GioiTinh] [int] NULL,
	[NgaySinh] [datetime] NULL,
	[DiaChi] [nvarchar](100) NULL,
	[DienThoai] [nchar](50) NULL,
	[MucCoDong] [float] NULL,
 CONSTRAINT [PK_BacSi] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[DanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucNgheNghiep]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DanhMucNgheNghiep](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
 CONSTRAINT [PK_NgheNghiep] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[DanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucLoaiBenhNhan]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DanhMucLoaiBenhNhan](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
 CONSTRAINT [PK_LoaiBenhNhan] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucDichVu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DanhMucDichVu](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
	[Gia] [float] NULL,
	[CoSuDung] [int] NULL,
 CONSTRAINT [PK_DanhMucBenh] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[DanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DanhMucBenhTienSu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DanhMucBenhTienSu](
	[Ma] [int] NOT NULL,
	[Ten] [nvarchar](50) NULL,
 CONSTRAINT [PK_DanhMucBenhTienSu] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BenhNhan](
	[Ma] [int] NOT NULL,
	[HoTen] [nvarchar](50) NULL,
	[GioiTinh] [int] NULL,
	[NgaySinh] [datetime] NULL,
	[DiaChi] [nvarchar](100) NULL,
	[MaQuan] [int] NULL,
	[DienThoai] [nchar](50) NULL,
	[MaNgheNghiep] [int] NULL,
	[MaLoai] [int] NULL,
	[KhamDinhKi] [int] NULL,
	[HinhAnh] [nvarchar](50) NULL,
	[ChiPhi] [float] NULL,
	[DuaTruoc] [float] NULL,
	[DaChupPhim] [int] NULL,
 CONSTRAINT [PK_BenhNhan] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDanhMucNgheNghiep]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDanhMucNgheNghiep]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDanhMucNgheNghiep]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DanhMucNgheNghiep]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDanhMucLoaiBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDanhMucLoaiBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDanhMucLoaiBenhNhan]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DanhMucLoaiBenhNhan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucDichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDanhMucDichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDanhMucDichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDanhMucDichVu]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DanhMucDichVu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDanhMucBenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDanhMucBenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDanhMucBenhTienSu]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DanhMucBenhTienSu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBacSi]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBacSi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteBacSi]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteBacSi]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[BacSi]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaBacSiMax]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaBacSiMax]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[usp_GetMaBacSiMax]	
AS
SET NOCOUNT ON

SELECT MAX(Ma) as Max
FROM BacSi
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteQuan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteQuan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteQuan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteQuan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteQuan]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[Quan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeletePhieu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeletePhieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeletePhieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeletePhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeletePhieu]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[Phieu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBacSi]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBacSi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBacSi]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertBacSi]
	@Ten nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@DienThoai nchar(50),
	@MucCoDong float,
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[BacSi] (
	[Ten],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[DienThoai],
	[MucCoDong]
) VALUES (
	@Ten,
	@GioiTinh,
	@NgaySinh,
	@DiaChi,
	@DienThoai,
	@MucCoDong
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaPhieuThuChiMax]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaPhieuThuChiMax]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[usp_GetMaPhieuThuChiMax]	
AS
SET NOCOUNT ON

SELECT MAX(Ma) as Max
FROM Phieu
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDanhMucNgheNghiep]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDanhMucNgheNghiep]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDanhMucNgheNghiep]
	@Ten nvarchar(50),
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DanhMucNgheNghiep] (
	[Ten]
) VALUES (
	@Ten
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDanhMucLoaiBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDanhMucLoaiBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDanhMucLoaiBenhNhan]
	@Ten nvarchar(50),
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DanhMucLoaiBenhNhan] (
	[Ten]
) VALUES (
	@Ten
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucDichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDanhMucDichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDanhMucDichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDanhMucDichVu]
	@Ten nvarchar(50),
	@Gia float,
	@CoSuDung int,
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DanhMucDichVu] (
	[Ten],
	[Gia],
	[CoSuDung]
) VALUES (
	@Ten,
	@Gia,
	@CoSuDung
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDanhMucBenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDanhMucBenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDanhMucBenhTienSu]
	@Ten nvarchar(50),
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DanhMucBenhTienSu] (
	[Ten]
) VALUES (
	@Ten
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBacSi]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBacSi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateBacSi]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateBacSi]
	@Ma int,
	@Ten nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@DienThoai nchar(50),
	@MucCoDong float
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[BacSi] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[BacSi] SET
		[Ten] = @Ten,
		[GioiTinh] = @GioiTinh,
		[NgaySinh] = @NgaySinh,
		[DiaChi] = @DiaChi,
		[DienThoai] = @DienThoai,
		[MucCoDong] = @MucCoDong
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[BacSi] (
		[Ma],
		[Ten],
		[GioiTinh],
		[NgaySinh],
		[DiaChi],
		[DienThoai],
		[MucCoDong]
	) VALUES (
		@Ma,
		@Ten,
		@GioiTinh,
		@NgaySinh,
		@DiaChi,
		@DienThoai,
		@MucCoDong
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertQuan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertQuan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertQuan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertQuan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertQuan]
	@Ten nvarchar(50),
	@Ma int OUTPUT
AS

SET NOCOUNT ON

INSERT INTO [dbo].[Quan] (
	[Ten]
) VALUES (
	@Ten
)

SET @Ma = SCOPE_IDENTITY()

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertPhieu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertPhieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertPhieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertPhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertPhieu]
	@Ngay datetime,
	@NguoiThucHien nvarchar(50),
	@DiaChi nvarchar(100),
	@DienThoai nvarchar(50),
	@NoiDung nvarchar(100),
	@SoTien float,
	@Loai int
AS

SET NOCOUNT ON

INSERT INTO [dbo].[Phieu] (
	[Ngay],
	[NguoiThucHien],
	[DiaChi],
	[DienThoai],
	[NoiDung],
	[SoTien],
	[Loai]
) VALUES (
	@Ngay,
	@NguoiThucHien,
	@DiaChi,
	@DienThoai,
	@NoiDung,
	@SoTien,
	@Loai
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDanhMucNgheNghiep]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDanhMucNgheNghiep]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDanhMucNgheNghiep]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[DanhMucNgheNghiep] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[DanhMucNgheNghiep] SET
		[Ten] = @Ten
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[DanhMucNgheNghiep] (
		[Ma],
		[Ten]
	) VALUES (
		@Ma,
		@Ten
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDanhMucLoaiBenhNhan]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[DanhMucLoaiBenhNhan] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[DanhMucLoaiBenhNhan] SET
		[Ten] = @Ten
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[DanhMucLoaiBenhNhan] (
		[Ma],
		[Ten]
	) VALUES (
		@Ma,
		@Ten
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucDichVu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucDichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDanhMucDichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDanhMucDichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDanhMucDichVu]
	@Ma int,
	@Ten nvarchar(50),
	@Gia float,
	@CoSuDung int
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[DanhMucDichVu] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[DanhMucDichVu] SET
		[Ten] = @Ten,
		[Gia] = @Gia,
		[CoSuDung] = @CoSuDung
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[DanhMucDichVu] (
		[Ma],
		[Ten],
		[Gia],
		[CoSuDung]
	) VALUES (
		@Ma,
		@Ten,
		@Gia,
		@CoSuDung
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDanhMucBenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDanhMucBenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDanhMucBenhTienSu]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[DanhMucBenhTienSu] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[DanhMucBenhTienSu] SET
		[Ten] = @Ten
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[DanhMucBenhTienSu] (
		[Ma],
		[Ten]
	) VALUES (
		@Ma,
		@Ten
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucNgheNghiepsAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucNgheNghiepsAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucNgheNghiepsAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucNgheNghiepsAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucNgheNghiepsAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucNgheNghiep]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucNgheNghiep]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucNgheNghiep]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucNgheNghiep]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucNgheNghiep]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucLoaiBenhNhansAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucLoaiBenhNhansAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucLoaiBenhNhan]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucLoaiBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucLoaiBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucLoaiBenhNhan]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucLoaiBenhNhan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucDichVusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucDichVusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucDichVusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucDichVusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucDichVusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten],
	[Gia],
	[CoSuDung]
FROM
	[dbo].[DanhMucDichVu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucDichVu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucDichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucDichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucDichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucDichVu]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten],
	[Gia],
	[CoSuDung]
FROM
	[dbo].[DanhMucDichVu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucBenhTienSusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucBenhTienSusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucBenhTienSusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucBenhTienSusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucBenhTienSusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucBenhTienSu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDanhMucBenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDanhMucBenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDanhMucBenhTienSu]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[DanhMucBenhTienSu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectQuansAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectQuansAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectQuansAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectQuansAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectQuansAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[Quan]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectQuan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectQuan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectQuan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectQuan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectQuan]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten]
FROM
	[dbo].[Quan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectPhieusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectPhieusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectPhieusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	convert(varchar(10), Ngay, 103)	as NgayThucHien,
	[Ngay],
	[NguoiThucHien],
	[DiaChi],
	[DienThoai],
	[NoiDung],
	[SoTien],
	[Loai]
FROM
	[dbo].[Phieu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieuByNgayDauNgayCuoi]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieuByNgayDauNgayCuoi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectPhieuByNgayDauNgayCuoi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectPhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectPhieuByNgayDauNgayCuoi]
	@ngaydau datetime,
	@ngaycuoi datetime
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ngay],
	[NguoiThucHien],
	[DiaChi],
	[DienThoai],
	[NoiDung],
	[SoTien],
	[Loai]
FROM
	[dbo].[Phieu]
WHERE
	([Ngay] > @ngaydau OR [Ngay] = @ngaydau) AND ([Ngay] < @ngaycuoi OR [Ngay] = @ngaycuoi)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectPhieu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectPhieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectPhieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectPhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectPhieu]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ngay],
	[NguoiThucHien],
	[DiaChi],
	[DienThoai],
	[NoiDung],
	[SoTien],
	[Loai]
FROM
	[dbo].[Phieu]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBacSisAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBacSisAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBacSisAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBacSisAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBacSisAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[DienThoai],
	[MucCoDong]
FROM
	[dbo].[BacSi]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBacSi]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBacSi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBacSi]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBacSi]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[Ten],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[DienThoai],
	[MucCoDong]
FROM
	[dbo].[BacSi]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateQuan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateQuan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateQuan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateQuan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateQuan]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[Quan] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[Quan] SET
		[Ten] = @Ten
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[Quan] (
		[Ma],
		[Ten]
	) VALUES (
		@Ma,
		@Ten
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdatePhieu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdatePhieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdatePhieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdatePhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdatePhieu]
	@Ma int,
	@Ngay datetime,
	@NguoiThucHien nvarchar(50),
	@DiaChi nvarchar(100),
	@DienThoai nvarchar(50),
	@NoiDung nvarchar(100),
	@SoTien float,
	@Loai int
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[Phieu] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[Phieu] SET
		[Ngay] = @Ngay,
		[NguoiThucHien] = @NguoiThucHien,
		[DiaChi] = @DiaChi,
		[DienThoai] = @DienThoai,
		[NoiDung] = @NoiDung,
		[SoTien] = @SoTien,
		[Loai] = @Loai
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[Phieu] (
		[Ma],
		[Ngay],
		[NguoiThucHien],
		[DiaChi],
		[DienThoai],
		[NoiDung],
		[SoTien],
		[Loai]
	) VALUES (
		@Ma,
		@Ngay,
		@NguoiThucHien,
		@DiaChi,
		@DienThoai,
		@NoiDung,
		@SoTien,
		@Loai
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateQuan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateQuan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateQuan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateQuan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateQuan]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[Quan] SET
	[Ten] = @Ten
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdatePhieu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdatePhieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdatePhieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdatePhieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdatePhieu]
	@Ma int,
	@Ngay datetime,
	@NguoiThucHien nvarchar(50),
	@DiaChi nvarchar(100),
	@DienThoai nchar(50),
	@NoiDung nvarchar(100),
	@SoTien float,
	@Loai int
AS

SET NOCOUNT ON

UPDATE [dbo].[Phieu] SET
	[Ngay] = @Ngay,
	[NguoiThucHien] = @NguoiThucHien,
	[DiaChi] = @DiaChi,
	[DienThoai] = @DienThoai,
	[NoiDung] = @NoiDung,
	[SoTien] = @SoTien,
	[Loai] = @Loai
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucNgheNghiep]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDanhMucNgheNghiep]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDanhMucNgheNghiep]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDanhMucNgheNghiep]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[DanhMucNgheNghiep] SET
	[Ten] = @Ten
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucLoaiBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDanhMucLoaiBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDanhMucLoaiBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDanhMucLoaiBenhNhan]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[DanhMucLoaiBenhNhan] SET
	[Ten] = @Ten
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucDichVu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucDichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDanhMucDichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDanhMucDichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDanhMucDichVu]
	@Ma int,
	@Ten nvarchar(50),
	@Gia float,
	@CoSuDung int
AS

SET NOCOUNT ON

UPDATE [dbo].[DanhMucDichVu] SET
	[Ten] = @Ten,
	[Gia] = @Gia,
	[CoSuDung] = @CoSuDung
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDanhMucBenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDanhMucBenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDanhMucBenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDanhMucBenhTienSu]
	@Ma int,
	@Ten nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[DanhMucBenhTienSu] SET
	[Ten] = @Ten
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBacSi]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBacSi]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateBacSi]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateBacSi]
	@Ma int,
	@Ten nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@DienThoai nchar(50),
	@MucCoDong float
AS

SET NOCOUNT ON

UPDATE [dbo].[BacSi] SET
	[Ten] = @Ten,
	[GioiTinh] = @GioiTinh,
	[NgaySinh] = @NgaySinh,
	[DiaChi] = @DiaChi,
	[DienThoai] = @DienThoai,
	[MucCoDong] = @MucCoDong
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateBenhNhan]
	@Ma int,
	@HoTen nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@MaQuan int,
	@DienThoai nchar(50),
	@MaNgheNghiep int,
	@MaLoai int,
	@KhamDinhKi int,
	@HinhAnh nvarchar(50),
	@ChiPhi float,
	@DuaTruoc float,
	@DaChupPhim int
AS

SET NOCOUNT ON

UPDATE [dbo].[BenhNhan] SET
	[HoTen] = @HoTen,
	[GioiTinh] = @GioiTinh,
	[NgaySinh] = @NgaySinh,
	[DiaChi] = @DiaChi,
	[MaQuan] = @MaQuan,
	[DienThoai] = @DienThoai,
	[MaNgheNghiep] = @MaNgheNghiep,
	[MaLoai] = @MaLoai,
	[KhamDinhKi] = @KhamDinhKi,
	[HinhAnh] = @HinhAnh,
	[ChiPhi] = @ChiPhi,
	[DuaTruoc] = @DuaTruoc,
	[DaChupPhim] = @DaChupPhim
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhanByThongTin]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhanByThongTin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_SelectBenhNhanByThongTin]	
	@Ma int,
	@Hoten nvarchar(50),
	@Gioitinh int,
	@Ngaysinh datetime
AS

SET NOCOUNT ON

SELECT*
FROM
	dbo.BenhNhan
WHERE
	HoTen like @hoten AND Ma = @ma AND GioiTinh = @gioitinh AND NgaySinh = @ngaysinh
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhanByHoTen]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhanByHoTen]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_SelectBenhNhanByHoTen]	
	@hoten nvarchar(50)
AS

SET NOCOUNT ON

SELECT *	
FROM
	dbo.BenhNhan
WHERE
	HoTen like ''%''+@hoten+''%''
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhan]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[HoTen],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[MaQuan],
	[DienThoai],
	[MaNgheNghiep],
	[MaLoai],
	[KhamDinhKi],
	[HinhAnh],
	[ChiPhi],
	[DuaTruoc],
	[DaChupPhim]
FROM
	[dbo].[BenhNhan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhansAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhansAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhansAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhansAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhansAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[HoTen],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[MaQuan],
	[DienThoai],
	[MaNgheNghiep],
	[MaLoai],
	[KhamDinhKi],
	[HinhAnh],
	[ChiPhi],
	[DuaTruoc],
	[DaChupPhim]
FROM
	[dbo].[BenhNhan]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateBenhNhan]
	@Ma int,
	@HoTen nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@MaQuan int,
	@DienThoai nchar(50),
	@MaNgheNghiep int,
	@MaLoai int,
	@KhamDinhKi int,
	@HinhAnh nvarchar(50),
	@ChiPhi float,
	@DuaTruoc float,
	@DaChupPhim int
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[BenhNhan] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[BenhNhan] SET
		[HoTen] = @HoTen,
		[GioiTinh] = @GioiTinh,
		[NgaySinh] = @NgaySinh,
		[DiaChi] = @DiaChi,
		[MaQuan] = @MaQuan,
		[DienThoai] = @DienThoai,
		[MaNgheNghiep] = @MaNgheNghiep,
		[MaLoai] = @MaLoai,
		[KhamDinhKi] = @KhamDinhKi,
		[HinhAnh] = @HinhAnh,
		[ChiPhi] = @ChiPhi,
		[DuaTruoc] = @DuaTruoc,
		[DaChupPhim] = @DaChupPhim
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[BenhNhan] (
		[Ma],
		[HoTen],
		[GioiTinh],
		[NgaySinh],
		[DiaChi],
		[MaQuan],
		[DienThoai],
		[MaNgheNghiep],
		[MaLoai],
		[KhamDinhKi],
		[HinhAnh],
		[ChiPhi],
		[DuaTruoc],
		[DaChupPhim]
	) VALUES (
		@Ma,
		@HoTen,
		@GioiTinh,
		@NgaySinh,
		@DiaChi,
		@MaQuan,
		@DienThoai,
		@MaNgheNghiep,
		@MaLoai,
		@KhamDinhKi,
		@HinhAnh,
		@ChiPhi,
		@DuaTruoc,
		@DaChupPhim
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_GetMaBNMax]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_GetMaBNMax]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_GetMaBNMax]	
AS

SET NOCOUNT ON

SELECT MAX(Ma) as Max
FROM BenhNhan

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertBenhNhan]
	@HoTen nvarchar(50),
	@GioiTinh int,
	@NgaySinh datetime,
	@DiaChi nvarchar(100),
	@MaQuan int,
	@DienThoai nchar(50),
	@MaNgheNghiep int,
	@MaLoai int,
	@KhamDinhKi int,
	@HinhAnh nvarchar(50),
	@ChiPhi float,
	@DuaTruoc float,
	@DaChupPhim int	
AS

SET NOCOUNT ON

INSERT INTO [dbo].[BenhNhan] (
	[HoTen],
	[GioiTinh],
	[NgaySinh],
	[DiaChi],
	[MaQuan],
	[DienThoai],
	[MaNgheNghiep],
	[MaLoai],
	[KhamDinhKi],
	[HinhAnh],
	[ChiPhi],
	[DuaTruoc],
	[DaChupPhim]
) VALUES (
	@HoTen,
	@GioiTinh,
	@NgaySinh,
	@DiaChi,
	@MaQuan,
	@DienThoai,
	@MaNgheNghiep,
	@MaLoai,
	@KhamDinhKi,
	@HinhAnh,
	@ChiPhi,
	@DuaTruoc,
	@DaChupPhim
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteBenhNhan]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteBenhNhan]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteBenhNhan]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[BenhNhan]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  Table [dbo].[DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DotDieuTri]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DotDieuTri](
	[Ma] [int] NOT NULL,
	[MaBenhNhan] [int] NULL,
	[NgayKham] [datetime] NULL,
	[MaBacSi] [int] NULL,
	[LyDoKham] [nvarchar](max) NULL,
	[ChanDoan] [nvarchar](max) NULL,
 CONSTRAINT [PK_DotDieuTri] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[LichHen]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LichHen]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LichHen](
	[Ma] [int] NOT NULL,
	[Ngay] [datetime] NULL,
	[MaBN] [int] NULL,
	[LyDo] [nvarchar](max) NULL,
 CONSTRAINT [PK_LichHen] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BenhNhan-Rang]    Script Date: 12/23/2012 13:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BenhNhan-Rang](
	[MaBN] [int] NOT NULL,
	[Rang] [nchar](10) NOT NULL,
	[Mat] [int] NOT NULL,
	[TinhTrang] [int] NULL,
	[ThongTin] [nvarchar](max) NULL,
 CONSTRAINT [PK_BenhNhan-Rang] PRIMARY KEY CLUSTERED 
(
	[MaBN] ASC,
	[Rang] ASC,
	[Mat] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BenhNhan-Phieu]    Script Date: 12/23/2012 13:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BenhNhan-Phieu](
	[MaBenhNhan] [int] NOT NULL,
	[MaPhieu] [int] NOT NULL,
	[GhiChu] [nvarchar](50) NULL,
 CONSTRAINT [PK_BenhNhan-Phieu] PRIMARY KEY CLUSTERED 
(
	[MaBenhNhan] ASC,
	[MaPhieu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[BenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[BenhNhan-BenhTienSu](
	[MaBenhNhan] [int] NOT NULL,
	[MaBenhTienSu] [int] NOT NULL,
	[GhiChu] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_BenhNhan-BenhTienSu] PRIMARY KEY CLUSTERED 
(
	[MaBenhNhan] ASC,
	[MaBenhTienSu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[ChiTietDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ChiTietDieuTri](
	[Ma] [int] NOT NULL,
	[MaBN] [int] NOT NULL,
	[MaDotDieuTri] [int] NULL,
	[MaDichVu] [int] NULL,
	[Ngay] [datetime] NULL,
	[Rang] [nchar](10) NULL,
	[CongViecDieuTri] [nvarchar](max) NULL,
	[GhiChu] [nvarchar](max) NULL,
	[ChiPhi] [float] NULL,
	[DuaTruoc] [float] NULL,
	[ConLai] [float] NULL,
 CONSTRAINT [PK_ChiTietDieuTri] PRIMARY KEY CLUSTERED 
(
	[Ma] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[DotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DotDieuTri-DichVu](
	[MaDotDieuTri] [int] NOT NULL,
	[MaDichVu] [int] NOT NULL,
	[ThucHien] [int] NULL,
	[MaTrangThai] [int] NULL,
 CONSTRAINT [PK_DotDieuTri-DichVu] PRIMARY KEY CLUSTERED 
(
	[MaDotDieuTri] ASC,
	[MaDichVu] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan-Phieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteBenhNhan-Phieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteBenhNhan-Phieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteBenhNhan-Phieu]
	@MaBenhNhan int,
	@MaPhieu int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[BenhNhan-Phieu]
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaPhieu] = @MaPhieu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteBenhNhan-BenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteBenhNhan-BenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteBenhNhan-BenhTienSu]
	@MaBenhNhan int,
	@MaBenhTienSu int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[BenhNhan-BenhTienSu]
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaBenhTienSu] = @MaBenhTienSu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDotDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDotDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDotDieuTri]
	@Ma int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DotDieuTri]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDotDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDotDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDotDieuTri]
	@MaBenhNhan int,
	@NgayKham datetime,
	@MaBacSi int,
	@LyDoKham nvarchar(max),
	@ChanDoan nvarchar(max)
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DotDieuTri] (
	[MaBenhNhan],
	[NgayKham],
	[MaBacSi],
	[LyDoKham],
	[ChanDoan]
) VALUES (
	@MaBenhNhan,
	@NgayKham,
	@MaBacSi,
	@LyDoKham,
	@ChanDoan
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan-Phieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBenhNhan-Phieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBenhNhan-Phieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertBenhNhan-Phieu]
	@MaBenhNhan int,
	@MaPhieu int,
	@GhiChu nvarchar(50)
AS

SET NOCOUNT ON

INSERT INTO [dbo].[BenhNhan-Phieu] (
	[MaBenhNhan],
	[MaPhieu],
	[GhiChu]
) VALUES (
	@MaBenhNhan,
	@MaPhieu,
	@GhiChu
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBenhNhan-BenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBenhNhan-BenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertBenhNhan-BenhTienSu]
	@MaBenhNhan int,
	@MaBenhTienSu int,
	@GhiChu nvarchar(max)
AS

SET NOCOUNT ON

INSERT INTO [dbo].[BenhNhan-BenhTienSu] (
	[MaBenhNhan],
	[MaBenhTienSu],
	[GhiChu]
) VALUES (
	@MaBenhNhan,
	@MaBenhTienSu,
	@GhiChu
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertBenhNhan_Rang]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertBenhNhan_Rang]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBacSi]
-- Date Generated: Thursday, September 01, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertBenhNhan_Rang]
	@mabn int,
	@rang nchar(10),
	@mat int,
	@tinhtrang int,
	@thongtin nvarchar(MAX)
AS

SET NOCOUNT ON

INSERT INTO [dbo].[BenhNhan-Rang] (
	[MaBN],
	[Rang],
	[Mat],
	[TinhTrang],
	[ThongTin]
) VALUES (
	@mabn,
	@rang,
	@mat,
	@tinhtrang,
	@thongtin
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-PhieusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-PhieusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhan-PhieusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhan-PhieusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhan-PhieusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaBenhNhan],
	[MaPhieu],
	[GhiChu]
FROM
	[dbo].[BenhNhan-Phieu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-Phieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhan-Phieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhan-Phieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhan-Phieu]
	@MaBenhNhan int,
	@MaPhieu int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaBenhNhan],
	[MaPhieu],
	[GhiChu]
FROM
	[dbo].[BenhNhan-Phieu]
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaPhieu] = @MaPhieu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDotDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDotDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDotDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDotDieuTri]
	@Ma int,
	@MaBenhNhan int,
	@NgayKham datetime,
	@MaBacSi int,
	@LyDoKham nvarchar(max),
	@ChanDoan nvarchar(max)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma] FROM [dbo].[DotDieuTri] WHERE [Ma] = @Ma)
BEGIN
	UPDATE [dbo].[DotDieuTri] SET
		[MaBenhNhan] = @MaBenhNhan,
		[NgayKham] = @NgayKham,
		[MaBacSi] = @MaBacSi,
		[LyDoKham] = @LyDoKham,
		[ChanDoan] = @ChanDoan
	WHERE
		[Ma] = @Ma
END
ELSE
BEGIN
	INSERT INTO [dbo].[DotDieuTri] (
		[Ma],
		[MaBenhNhan],
		[NgayKham],
		[MaBacSi],
		[LyDoKham],
		[ChanDoan]
	) VALUES (
		@Ma,
		@MaBenhNhan,
		@NgayKham,
		@MaBacSi,
		@LyDoKham,
		@ChanDoan
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-BenhTienSusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-BenhTienSusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhan-BenhTienSusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhan-BenhTienSusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhan-BenhTienSusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaBenhNhan],
	[MaBenhTienSu],
	[GhiChu]
FROM
	[dbo].[BenhNhan-BenhTienSu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectBenhNhan-BenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectBenhNhan-BenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectBenhNhan-BenhTienSu]
	@MaBenhNhan int,
	@MaBenhTienSu int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaBenhNhan],
	[MaBenhTienSu],
	[GhiChu]
FROM
	[dbo].[BenhNhan-BenhTienSu]
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaBenhTienSu] = @MaBenhTienSu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan-Phieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateBenhNhan-Phieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateBenhNhan-Phieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateBenhNhan-Phieu]
	@MaBenhNhan int,
	@MaPhieu int,
	@GhiChu nvarchar(50)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [MaBenhNhan], [MaPhieu] FROM [dbo].[BenhNhan-Phieu] WHERE [MaBenhNhan] = @MaBenhNhan AND [MaPhieu] = @MaPhieu)
BEGIN
	UPDATE [dbo].[BenhNhan-Phieu] SET
		[GhiChu] = @GhiChu
	WHERE
		[MaBenhNhan] = @MaBenhNhan
		AND [MaPhieu] = @MaPhieu
END
ELSE
BEGIN
	INSERT INTO [dbo].[BenhNhan-Phieu] (
		[MaBenhNhan],
		[MaPhieu],
		[GhiChu]
	) VALUES (
		@MaBenhNhan,
		@MaPhieu,
		@GhiChu
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateBenhNhan-BenhTienSu]
	@MaBenhNhan int,
	@MaBenhTienSu int,
	@GhiChu nvarchar(max)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [MaBenhNhan], [MaBenhTienSu] FROM [dbo].[BenhNhan-BenhTienSu] WHERE [MaBenhNhan] = @MaBenhNhan AND [MaBenhTienSu] = @MaBenhTienSu)
BEGIN
	UPDATE [dbo].[BenhNhan-BenhTienSu] SET
		[GhiChu] = @GhiChu
	WHERE
		[MaBenhNhan] = @MaBenhNhan
		AND [MaBenhTienSu] = @MaBenhTienSu
END
ELSE
BEGIN
	INSERT INTO [dbo].[BenhNhan-BenhTienSu] (
		[MaBenhNhan],
		[MaBenhTienSu],
		[GhiChu]
	) VALUES (
		@MaBenhNhan,
		@MaBenhTienSu,
		@GhiChu
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateBenhNhan_Rang]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateBenhNhan_Rang]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertBacSi]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertBacSi]
-- Date Generated: Thursday, September 01, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateBenhNhan_Rang]
	@mabn int,
	@rang nchar(10),
	@mat int,
	@tinhtrang int,
	@thongtin nvarchar(MAX)
AS

SET NOCOUNT ON

IF EXISTS(SELECT [MaBN], [Rang], [Mat] FROM [dbo].[BenhNhan-Rang] WHERE [MaBN] = @mabn AND [Rang] = @rang AND [Mat] = @mat)
BEGIN
	UPDATE [dbo].[BenhNhan-Rang] SET
		[TinhTrang] = @tinhtrang,
		[ThongTin] = @thongtin
	WHERE
		[MaBN] = @mabn 
		AND [Rang] = @rang
		AND [Mat] = @mat
END
ELSE
BEGIN
	INSERT INTO [dbo].[BenhNhan-Rang] (
	[MaBN],
	[Rang],
	[Mat],
	[TinhTrang],
	[ThongTin]
) VALUES (
	@mabn,
	@rang,
	@mat,
	@tinhtrang,
	@thongtin
)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_SelectAllDotDieuTriByMaBenhNhan]
	@Ma int
AS

SET NOCOUNT ON

SELECT
	Ma,
	NgayKham
FROM
	dbo.DotDieuTri 
WHERE
	MaBenhNhan=@Ma
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTrisAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTrisAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDotDieuTrisAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDotDieuTrisAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDotDieuTrisAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[MaBenhNhan],
	[NgayKham],
	[MaBacSi],
	[LyDoKham],
	[ChanDoan]
FROM
	[dbo].[DotDieuTri]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDotDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDotDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDotDieuTri]
	@Ma int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[MaBenhNhan],
	[NgayKham],
	[MaBacSi],
	[LyDoKham],
	[ChanDoan]
FROM
	[dbo].[DotDieuTri]
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectRangByMaBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectRangByMaBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_SelectRangByMaBenhNhan]
	@Ma int
AS

SET NOCOUNT ON

SELECT
	*
FROM
	dbo.[BenhNhan-Rang] 
WHERE
	MaBN=@Ma
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDotDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDotDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDotDieuTri]
	@Ma int,
	@MaBenhNhan int,
	@NgayKham datetime,
	@MaBacSi int,
	@LyDoKham nvarchar(max),
	@ChanDoan nvarchar(max)
AS

SET NOCOUNT ON

UPDATE [dbo].[DotDieuTri] SET
	[MaBenhNhan] = @MaBenhNhan,
	[NgayKham] = @NgayKham,
	[MaBacSi] = @MaBacSi,
	[LyDoKham] = @LyDoKham,
	[ChanDoan] = @ChanDoan
WHERE
	[Ma] = @Ma

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan-Phieu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan-Phieu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateBenhNhan-Phieu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateBenhNhan-Phieu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateBenhNhan-Phieu]
	@MaBenhNhan int,
	@MaPhieu int,
	@GhiChu nvarchar(50)
AS

SET NOCOUNT ON

UPDATE [dbo].[BenhNhan-Phieu] SET
	[GhiChu] = @GhiChu
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaPhieu] = @MaPhieu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateBenhNhan-BenhTienSu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateBenhNhan-BenhTienSu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateBenhNhan-BenhTienSu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateBenhNhan-BenhTienSu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateBenhNhan-BenhTienSu]
	@MaBenhNhan int,
	@MaBenhTienSu int,
	@GhiChu nvarchar(max)
AS

SET NOCOUNT ON

UPDATE [dbo].[BenhNhan-BenhTienSu] SET
	[GhiChu] = @GhiChu
WHERE
	[MaBenhNhan] = @MaBenhNhan
	AND [MaBenhTienSu] = @MaBenhTienSu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateDotDieuTri-DichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateDotDieuTri-DichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateDotDieuTri-DichVu]
	@MaDotDieuTri int,
	@MaDichVu int,
	@ThucHien int,
	@MaTrangThai int
AS

SET NOCOUNT ON

UPDATE [dbo].[DotDieuTri-DichVu] SET
	[ThucHien] = @ThucHien,
	[MaTrangThai] = @MaTrangThai
WHERE
	[MaDotDieuTri] = @MaDotDieuTri
	AND [MaDichVu] = @MaDichVu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_UpdateChiTietDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_UpdateChiTietDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_UpdateChiTietDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_UpdateChiTietDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_UpdateChiTietDieuTri]
	@Ma int,
	@MaDotDieuTri int,
	@MaDichVu int,
	@Ngay datetime,
	@Rang nchar(10),
	@CongViecDieuTri nvarchar(max),
	@GhiChu nvarchar(max),
	@ChiPhi float,
	@DuaTruoc float,
	@ConLai float
AS

SET NOCOUNT ON

UPDATE [dbo].[ChiTietDieuTri] SET
	[MaDichVu] = @MaDichVu,
	[Ngay] = @Ngay,
	[Rang] = @Rang,
	[CongViecDieuTri] = @CongViecDieuTri,
	[GhiChu] = @GhiChu,
	[ChiPhi] = @ChiPhi,
	[DuaTruoc] = @DuaTruoc,
	[ConLai] = @ConLai
WHERE
	[Ma] = @Ma
	AND [MaDotDieuTri] = @MaDotDieuTri

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri-DichVusAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri-DichVusAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDotDieuTri-DichVusAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDotDieuTri-DichVusAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDotDieuTri-DichVusAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaDotDieuTri],
	[MaDichVu],
	[ThucHien],
	[MaTrangThai]
FROM
	[dbo].[DotDieuTri-DichVu]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectDotDieuTri-DichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectDotDieuTri-DichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectDotDieuTri-DichVu]
	@MaDotDieuTri int,
	@MaDichVu int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[MaDotDieuTri],
	[MaDichVu],
	[ThucHien],
	[MaTrangThai]
FROM
	[dbo].[DotDieuTri-DichVu]
WHERE
	[MaDotDieuTri] = @MaDotDieuTri
	AND [MaDichVu] = @MaDichVu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTrisAll]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTrisAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectChiTietDieuTrisAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectChiTietDieuTrisAll]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectChiTietDieuTrisAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[MaDotDieuTri],
	[MaDichVu],
	[Ngay],
	[Rang],
	[CongViecDieuTri],
	[GhiChu],
	[ChiPhi],
	[DuaTruoc],
	[ConLai]
FROM
	[dbo].[ChiTietDieuTri]

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTriByDotDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTriByDotDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[usp_SelectChiTietDieuTriByDotDieuTri]	
	@MaDDT int
AS

SET NOCOUNT ON

SELECT
	ct.Ma,
	ct.MaDichVu,
	ct.MaDotDieuTri,
	ct.Ngay,
	ct.Rang,
	ct.CongViecDieuTri,
	ct.GhiChu,
	ct.DuaTruoc,
	ct.ChiPhi,
	ct.ConLai
FROM
	dbo.ChiTietDieuTri as ct
	
WHERE
	ct.MaDotDieuTri=@MaDDT
' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectChiTietDieuTri]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectChiTietDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_SelectChiTietDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectChiTietDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_SelectChiTietDieuTri]
	@Ma int,
	@MaDotDieuTri int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
	[Ma],
	[MaDotDieuTri],
	[MaDichVu],
	[Ngay],
	[Rang],
	[CongViecDieuTri],
	[GhiChu],
	[ChiPhi],
	[DuaTruoc],
	[ConLai]
FROM
	[dbo].[ChiTietDieuTri]
WHERE
	[Ma] = @Ma
	AND [MaDotDieuTri] = @MaDotDieuTri

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- Batch submitted through debugger: SQLQuery4.sql|7|0|C:\Users\TuanAnh\AppData\Local\Temp\~vs9E6A.sql
-- Batch submitted through debugger: SQLQuery1.sql|7|0|C:\Users\TuanAnh\AppData\Local\Temp\~vs6DB3.sql

CREATE PROCEDURE [dbo].[usp_SelectAllChiTietDieuTriByBenhNhan]	
	@mabn int	
AS

SET NOCOUNT ON

SELECT
	ct.Ma,
	ct.MaDichVu,
	ct.MaDotDieuTri,
	ct.Ngay,
	ct.Rang,
	ct.CongViecDieuTri,
	ct.GhiChu,
	ct.DuaTruoc,
	ct.ChiPhi,
	ct.ConLai
FROM
	dbo.DotDieuTri as ddt,
	dbo.ChiTietDieuTri as ct
WHERE
	ddt.MaBenhNhan = @mabn AND ddt.Ma = ct.MaDotDieuTri
ORDER BY
	ct.Rang,ct.Ngay' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateDotDieuTri-DichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateDotDieuTri-DichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateDotDieuTri-DichVu]
	@MaDotDieuTri int,
	@MaDichVu int,
	@ThucHien int,
	@MaTrangThai int
AS

SET NOCOUNT ON

IF EXISTS(SELECT [MaDotDieuTri], [MaDichVu] FROM [dbo].[DotDieuTri-DichVu] WHERE [MaDotDieuTri] = @MaDotDieuTri AND [MaDichVu] = @MaDichVu)
BEGIN
	UPDATE [dbo].[DotDieuTri-DichVu] SET
		[ThucHien] = @ThucHien,
		[MaTrangThai] = @MaTrangThai
	WHERE
		[MaDotDieuTri] = @MaDotDieuTri
		AND [MaDichVu] = @MaDichVu
END
ELSE
BEGIN
	INSERT INTO [dbo].[DotDieuTri-DichVu] (
		[MaDotDieuTri],
		[MaDichVu],
		[ThucHien],
		[MaTrangThai]
	) VALUES (
		@MaDotDieuTri,
		@MaDichVu,
		@ThucHien,
		@MaTrangThai
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertUpdateChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertUpdateChiTietDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertUpdateChiTietDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertUpdateChiTietDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertUpdateChiTietDieuTri]
	@Ma int,
	@MaDotDieuTri int,
	@MaDichVu int,
	@Ngay datetime,
	@Rang nchar(10),
	@CongViecDieuTri nvarchar(max),
	@GhiChu nvarchar(max),
	@ChiPhi float,
	@DuaTruoc float,
	@ConLai float
AS

SET NOCOUNT ON

IF EXISTS(SELECT [Ma], [MaDotDieuTri] FROM [dbo].[ChiTietDieuTri] WHERE [Ma] = @Ma AND [MaDotDieuTri] = @MaDotDieuTri)
BEGIN
	UPDATE [dbo].[ChiTietDieuTri] SET
		[MaDichVu] = @MaDichVu,
		[Ngay] = @Ngay,
		[Rang] = @Rang,
		[CongViecDieuTri] = @CongViecDieuTri,
		[GhiChu] = @GhiChu,
		[ChiPhi] = @ChiPhi,
		[DuaTruoc] = @DuaTruoc,
		[ConLai] = @ConLai
	WHERE
		[Ma] = @Ma
		AND [MaDotDieuTri] = @MaDotDieuTri
END
ELSE
BEGIN
	INSERT INTO [dbo].[ChiTietDieuTri] (
		[Ma],
		[MaDotDieuTri],
		[MaDichVu],
		[Ngay],
		[Rang],
		[CongViecDieuTri],
		[GhiChu],
		[ChiPhi],
		[DuaTruoc],
		[ConLai]
	) VALUES (
		@Ma,
		@MaDotDieuTri,
		@MaDichVu,
		@Ngay,
		@Rang,
		@CongViecDieuTri,
		@GhiChu,
		@ChiPhi,
		@DuaTruoc,
		@ConLai
	)
END

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertDotDieuTri-DichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertDotDieuTri-DichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertDotDieuTri-DichVu]
	@MaDotDieuTri int,
	@MaDichVu int,
	@ThucHien int,
	@MaTrangThai int
AS

SET NOCOUNT ON

INSERT INTO [dbo].[DotDieuTri-DichVu] (
	[MaDotDieuTri],
	[MaDichVu],
	[ThucHien],
	[MaTrangThai]
) VALUES (
	@MaDotDieuTri,
	@MaDichVu,
	@ThucHien,
	@MaTrangThai
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_InsertChiTietDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_InsertChiTietDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_InsertChiTietDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_InsertChiTietDieuTri]
	@Ma int,
	@MaDotDieuTri int,
	@MaDichVu int,
	@Ngay datetime,
	@Rang nchar(10),
	@CongViecDieuTri nvarchar(max),
	@GhiChu nvarchar(max),
	@ChiPhi float,
	@DuaTruoc float,
	@ConLai float
AS

SET NOCOUNT ON

INSERT INTO [dbo].[ChiTietDieuTri] (
	[Ma],
	[MaDotDieuTri],
	[MaDichVu],
	[Ngay],
	[Rang],
	[CongViecDieuTri],
	[GhiChu],
	[ChiPhi],
	[DuaTruoc],
	[ConLai]
) VALUES (
	@Ma,
	@MaDotDieuTri,
	@MaDichVu,
	@Ngay,
	@Rang,
	@CongViecDieuTri,
	@GhiChu,
	@ChiPhi,
	@DuaTruoc,
	@ConLai
)

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteDotDieuTri-DichVu]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteDotDieuTri-DichVu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteDotDieuTri-DichVu]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteDotDieuTri-DichVu]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteDotDieuTri-DichVu]
	@MaDotDieuTri int,
	@MaDichVu int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[DotDieuTri-DichVu]
WHERE
	[MaDotDieuTri] = @MaDotDieuTri
	AND [MaDichVu] = @MaDichVu

--endregion

' 
END
GO
/****** Object:  StoredProcedure [dbo].[usp_DeleteChiTietDieuTri]    Script Date: 12/23/2012 13:49:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_DeleteChiTietDieuTri]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--region [dbo].[usp_DeleteChiTietDieuTri]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   TuanAnh using CodeSmith 5.0.0.0
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_DeleteChiTietDieuTri]
-- Date Generated: Sunday, September 11, 2011
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[usp_DeleteChiTietDieuTri]
	@Ma int,
	@MaDotDieuTri int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[ChiTietDieuTri]
WHERE
	[Ma] = @Ma
	AND [MaDotDieuTri] = @MaDotDieuTri

--endregion

' 
END
GO
/****** Object:  ForeignKey [FK_BenhNhan_DanhMucLoaiBenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucLoaiBenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan_DanhMucLoaiBenhNhan] FOREIGN KEY([MaLoai])
REFERENCES [dbo].[DanhMucLoaiBenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucLoaiBenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] CHECK CONSTRAINT [FK_BenhNhan_DanhMucLoaiBenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan_DanhMucNgheNghiep]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucNgheNghiep]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan_DanhMucNgheNghiep] FOREIGN KEY([MaNgheNghiep])
REFERENCES [dbo].[DanhMucNgheNghiep] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_DanhMucNgheNghiep]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] CHECK CONSTRAINT [FK_BenhNhan_DanhMucNgheNghiep]
GO
/****** Object:  ForeignKey [FK_BenhNhan_Quan]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_Quan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan_Quan] FOREIGN KEY([MaQuan])
REFERENCES [dbo].[Quan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan_Quan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan]'))
ALTER TABLE [dbo].[BenhNhan] CHECK CONSTRAINT [FK_BenhNhan_Quan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-BenhTienSu_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan-BenhTienSu_BenhNhan] FOREIGN KEY([MaBenhNhan])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] CHECK CONSTRAINT [FK_BenhNhan-BenhTienSu_BenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu] FOREIGN KEY([MaBenhTienSu])
REFERENCES [dbo].[DanhMucBenhTienSu] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-BenhTienSu]'))
ALTER TABLE [dbo].[BenhNhan-BenhTienSu] CHECK CONSTRAINT [FK_BenhNhan-BenhTienSu_DanhMucBenhTienSu]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Phieu_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan-Phieu_BenhNhan] FOREIGN KEY([MaBenhNhan])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] CHECK CONSTRAINT [FK_BenhNhan-Phieu_BenhNhan]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Phieu_Phieu]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_Phieu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan-Phieu_Phieu] FOREIGN KEY([MaPhieu])
REFERENCES [dbo].[Phieu] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Phieu_Phieu]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Phieu]'))
ALTER TABLE [dbo].[BenhNhan-Phieu] CHECK CONSTRAINT [FK_BenhNhan-Phieu_Phieu]
GO
/****** Object:  ForeignKey [FK_BenhNhan-Rang_BenhNhan]    Script Date: 12/23/2012 13:49:57 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Rang_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]'))
ALTER TABLE [dbo].[BenhNhan-Rang]  WITH CHECK ADD  CONSTRAINT [FK_BenhNhan-Rang_BenhNhan] FOREIGN KEY([MaBN])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BenhNhan-Rang_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[BenhNhan-Rang]'))
ALTER TABLE [dbo].[BenhNhan-Rang] CHECK CONSTRAINT [FK_BenhNhan-Rang_BenhNhan]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri]  WITH CHECK ADD  CONSTRAINT [FK_ChiTietDieuTri_BenhNhan] FOREIGN KEY([MaBN])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] CHECK CONSTRAINT [FK_ChiTietDieuTri_BenhNhan]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri]  WITH CHECK ADD  CONSTRAINT [FK_ChiTietDieuTri_DanhMucDichVu] FOREIGN KEY([MaDichVu])
REFERENCES [dbo].[DanhMucDichVu] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] CHECK CONSTRAINT [FK_ChiTietDieuTri_DanhMucDichVu]
GO
/****** Object:  ForeignKey [FK_ChiTietDieuTri_DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri]  WITH CHECK ADD  CONSTRAINT [FK_ChiTietDieuTri_DotDieuTri] FOREIGN KEY([MaDotDieuTri])
REFERENCES [dbo].[DotDieuTri] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ChiTietDieuTri_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[ChiTietDieuTri]'))
ALTER TABLE [dbo].[ChiTietDieuTri] CHECK CONSTRAINT [FK_ChiTietDieuTri_DotDieuTri]
GO
/****** Object:  ForeignKey [FK_DotDieuTri_BacSi]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BacSi]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri]  WITH CHECK ADD  CONSTRAINT [FK_DotDieuTri_BacSi] FOREIGN KEY([MaBacSi])
REFERENCES [dbo].[BacSi] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BacSi]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] CHECK CONSTRAINT [FK_DotDieuTri_BacSi]
GO
/****** Object:  ForeignKey [FK_DotDieuTri_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri]  WITH CHECK ADD  CONSTRAINT [FK_DotDieuTri_BenhNhan] FOREIGN KEY([MaBenhNhan])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri]'))
ALTER TABLE [dbo].[DotDieuTri] CHECK CONSTRAINT [FK_DotDieuTri_BenhNhan]
GO
/****** Object:  ForeignKey [FK_DotDieuTri-DichVu_DanhMucDichVu]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu]  WITH CHECK ADD  CONSTRAINT [FK_DotDieuTri-DichVu_DanhMucDichVu] FOREIGN KEY([MaDichVu])
REFERENCES [dbo].[DanhMucDichVu] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DanhMucDichVu]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] CHECK CONSTRAINT [FK_DotDieuTri-DichVu_DanhMucDichVu]
GO
/****** Object:  ForeignKey [FK_DotDieuTri-DichVu_DotDieuTri]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu]  WITH CHECK ADD  CONSTRAINT [FK_DotDieuTri-DichVu_DotDieuTri] FOREIGN KEY([MaDotDieuTri])
REFERENCES [dbo].[DotDieuTri] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_DotDieuTri-DichVu_DotDieuTri]') AND parent_object_id = OBJECT_ID(N'[dbo].[DotDieuTri-DichVu]'))
ALTER TABLE [dbo].[DotDieuTri-DichVu] CHECK CONSTRAINT [FK_DotDieuTri-DichVu_DotDieuTri]
GO
/****** Object:  ForeignKey [FK_LichHen_BenhNhan]    Script Date: 12/23/2012 13:49:58 ******/
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LichHen_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[LichHen]'))
ALTER TABLE [dbo].[LichHen]  WITH CHECK ADD  CONSTRAINT [FK_LichHen_BenhNhan] FOREIGN KEY([MaBN])
REFERENCES [dbo].[BenhNhan] ([Ma])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_LichHen_BenhNhan]') AND parent_object_id = OBJECT_ID(N'[dbo].[LichHen]'))
ALTER TABLE [dbo].[LichHen] CHECK CONSTRAINT [FK_LichHen_BenhNhan]
GO
